﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SonCa.SocialNetwork.Web.ASCX.Presenters;
using SonCa.SocialNetwork.Web.ASCX.IPresenters;
using SonCa.SocialNetwork.Web.HelperClass;
using System.ComponentModel.Composition;
using Core.Common;
using Core.Interfaces;

namespace SonCa.SN.ASCX
{
    public partial class HomeHeader : System.Web.UI.UserControl, IHeaderPresenter
    {
        protected HeaderPresenter _presenter;
        [Import]
        private IWebContext _webContext;

        protected void Page_Load(object sender, EventArgs e)
        {
            _presenter = new HeaderPresenter();
            _presenter.Init(this);
            MEFManager.Compose(this);

            int countInvitation = _presenter.CountFriendRequestInvitation();
            int countMessage = _presenter.CountMessages();
            int count = countInvitation + countMessage;

            hdfAccoutnID.Value = _presenter.GetCurrentAccountID().ToString();
            lblCountInviteFriend.Text = count > 0 ? count.ToString() : "";
            lblLUserName.Text = !string.IsNullOrEmpty(_webContext.UserName) ? _webContext.UserName : string.Empty;

            int countMessageChat = _presenter.CountMessageChat();
            lblCountMessage.Text = countMessageChat > 0 ? countMessageChat.ToString() : "";
        }

        protected void lbLogout_Click(object sender, EventArgs e)
        {
            _presenter.Logout();
        }
    }
}